using Digitalmes.Domain.Entities.Mes.Masters;

namespace Digitalmes.Application.Mes.Masters.Lines.Queries;

/// <summary>
/// 产线查询命令，包含工站信息。
/// </summary>
public sealed record GetAllLineListQuery : IRequest<IResult<List<MdLineDto>>>;

internal sealed class GetAllLineListQueryHandler(IRepository<MdLine> repo) : IRequestHandler<GetAllLineListQuery, IResult<List<MdLineDto>>>
{
    public async Task<IResult<List<MdLineDto>>> Handle(GetAllLineListQuery request, CancellationToken cancellationToken)
    {
        var items = await repo.AsQueryable()
            .Includes(m => m.Workstations!.OrderBy(t => t.Order).ToList())
            .OrderBy(m => m.Order)
            .ToListAsync(cancellationToken);
        return Result.From(items.Adapt<List<MdLineDto>>());
    }
}
